import { createApp } from 'vue'
import { getFetchEnv } from './utils/fetch-env'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from './http/axios'
import './common/browser_patch'

// element 相关配置导入
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn'
import * as ElIconList from '@element-plus/icons-vue'
// import infiniteScroll from 'vue3-infinite-scroll-better'

// 引入文件保存、导出
import FileSaver from 'file-saver'

var app = createApp(App)

// app.config.globalProperties.BACKEND_URL = 'http://192.168.0.231:8081';

getFetchEnv().then((fetchEnv) => {
    app.config.globalProperties.BACKEND_URL = fetchEnv.server_url;
    // BACKEND_URL = fetchEnv.server_url
}).catch((error) => {
    console.error('Failed to fetch environment', error);
});

// 全局引用图标
for (const name in ElIconList) {
    app.component(name, ElIconList[name])
}

app.config.globalProperties.$fileSaver = FileSaver;
// app.config.globalProperties.$XLSX = XLSX;

app.config.globalProperties.$http = axios
axios.defaults.baseURL = '' //配置请求跟路径

app.config.globalProperties.$Message = ElementPlus.Message
app.config.globalProperties.$confirm = ElementPlus.confirm

app.use(ElementPlus, { locale })
app.use(store)
app.use(router)
// app.use(infiniteScroll)
app.mount('#app')
// createApp(App).use(store).use(router).mount('#app')
